package com.song.shop;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.connection.jedis.JedisUtils;
import redis.clients.jedis.Jedis;
import sun.misc.Cleaner;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;

/**
 * @author Song Yinghui
 * @date 2018/8/22
 * @Version 1.0
 * @Descp 使用jedis 直接调用lua脚本
 */
public class Branchtest extends BugTest {

    private String lockVal = Thread.currentThread().getName() + "_" + UUID.randomUUID().toString();
    private Jedis jedis ;
    public Branchtest(){
        jedis = new Jedis("111.231.232.212" , 6379);
        jedis.auth("redisroot");
    }

    public void lock(){

        String lockScript = "if redis.call('SETNX',KEYS[1],ARGV[1]) == 1 then redis.call('EXPIRE', KEYS[1],tonumber(ARGV[2])) return ARGV[3] else return '0' end";
        Object songying = jedis.eval(lockScript, 1, "songying", lockVal, "6000", "1");
        System.out.println("lockVal=="+lockVal);
        System.out.println("result === "+songying);

    }

    public static void main(String[] args){
        Branchtest branchtest = new Branchtest();
        //branchtest.lock();
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(2018,06,29);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(2018,11,20);
        long i = calendar2.getTime().getTime() - calendar1.getTime().getTime();
        System.out.println(i/(1000 * 60 * 60 * 24));

    }
}
